<template>
  <ul class="section-list">
    <li v-for="(item, index) in list" :key="index">
      <div
        class="dir-name-wrapper flex-center-wrap flex-justify-between"
        v-if="+item.option_type === 1"
        @click.stop="toggleDir(item, index)"
      >
        <div
          class="flex-center dir-icon-box"
          :class="{ 'dir-second-icon-rotate': item.isExpand }"
        >
          <i class="iconfont icon-youjiantou dir-second-icon"></i>
        </div>
        <div class="dir-name" :style="{ 'max-width': itemWidth(maxWidth) }">
          {{ item.dir_name }}
        </div>
        <div class="dir-r flex1"></div>
      </div>
      <play-section v-else :section="item" />
      <playItem
        v-if="item.children && item.children.length && item.isExpand"
        :children="item.children"
      ></playItem>
    </li>
  </ul>
</template>
<script>
import playSection from '@/components/play/playSection.vue'
export default {
  name: 'playItem',
  components: {
    'play-section': playSection
  },
  props: {
    children: {
      type: Array,
      default: () => []
    },
    maxWidth: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      list: this.children
      // listMaxWidth: ''
    }
  },
  computed: {},
  methods: {
    // 选中播放
    // chooseSection(item) {
    //   this.$store.dispatch('play/getPlayingSection', item)
    // }
    // 控制展开关闭文件夹
    toggleDir(item, index) {
      item.isExpand = !item.isExpand
      this.$forceUpdate()
    },
    itemWidth(length) {
      return length.slice(0, -2) - 30 + 'px' ? length : '190px'
    }
  },
  mounted() {
    this.$bus.$on('openDir2', val => {
      this.list.forEach(item => {
        if (+item.dir_id === +val.dir.dir_id) {
          item.isExpand = true
        }
      })
    })
  }
}
</script>
<style scoped>
.dir-name-wrapper {
  margin-left: 16px;
  padding: 10px 20px;
  cursor: pointer;
}

.dir-name {
  /* width: 190px; */
  font-size: 15px;
  color: #e6e6e6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dir-icon-box {
  transition: all 0.1s ease;
  margin-right: 6px;
  width: 16px;
  height: 16px;
}
.dir-second-icon {
  font-size: 12px;
  color: #e6e6e6;
}
.section-list {
  /* margin-top: -10px; */
  /* margin-bottom: 20px; */
}
.dir-second-icon-rotate {
  transform: rotate(90deg);
}
</style>
